<?php
namespace Mobile\Controller;
use Think\Controller;
class InfoController extends Controller 
{
    //判断是老师还是家长
    public function is_home()
    {
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);

        if (!isset($_SESSION['id'])) {
            $this->redirect('mobile/user/login',array('newcity'=>$city));
        }else {
            //laoshi
            if ($_SESSION['is_who'] == 'laoshi') {
                $this->redirect('mobile/info/ls_home',array('newcity'=>$city));
            }else {
                $this->redirect('mobile/info/jz_home',array('newcity'=>$city));
            }
        }

    }

	//老师个人主页
    public function ls_home()
    {
        if ($_SESSION['is_who'] != 'laoshi') {
            $this->redirect('mobile/user/logout');
            exit;
        }

        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);

        //老师信息
        $laoshi_info = M('laoshi_user')->field('id,phone,face')->where(array('id'=>$_SESSION['id']))->find();
        $this->assign('laoshi_info',$laoshi_info);

        $this->display();
    }

    //老师个人主页 身份验证/证件上传
    public function ls_info()
    {
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);

        $id = $_SESSION['id'];
        $laoshi_sfz = M('laoshi_user')->where(array('id'=>$id))->field('sfz_name,sfz_num,sfz_img,jiaoshizheng_img,qitazheng_img')->find();
        $this->assign('laoshi_sfz',$laoshi_sfz);
        //print_r($laoshi_sfz);

        $this->display();
    }
    //身份证姓名修改
    public function sfz_name()
    { 
       if (IS_POST) {
        //身份证姓名入库
        $data['sfz_name'] = I('post.sfz_name');
        //姓名验证
        if (empty($data['sfz_name'])) { 
            $arr = array(
                'error' =>0,
                'info' => '请输入正确的姓名'    
                );
            echo json_encode($arr);
            exit;
        }
        //入库
        $res = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('sfz_name',$data['sfz_name']);
            if ($res) {
                $arr = array(
                    'error' =>1,
                    'info' => '姓名修改成功'  
                    );
                echo json_encode($arr);
            }else{
                $arr = array(
                    'error' =>0,
                    'info' => '姓名修改失败'  
                    );
                echo json_encode($arr);
            }
       }
    }
    //身份证号码修改
    public function sfz_num()
    { 
       if (IS_POST) {
        //身份证姓名入库
        $data['sfz_num'] = I('post.sfz');
        //身份证
        $sfz_yz = preg_match("/^(\d{18,18}|\d{15,15}|\d{17,17}x)$/",$data['sfz_num']);
        if (!$sfz_yz) {
            $arr = array(
                'error' =>0,
                'info' => '请输入正确的身份证号'  
                );
            echo json_encode($arr);
            exit;
        }
        //入库
        $res = M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('sfz_num',$data['sfz_num']);
            if ($res) {
                $arr = array(
                    'error' =>1,
                    'info' => '身份证号修改成功'    
                    );
                echo json_encode($arr);
            }else{
                $arr = array(
                    'error' =>0,
                    'info' => '身份证号修改失败'    
                    );
                echo json_encode($arr);
            }
       }
    }
    //身份证照片修改
    public function sfz_img()
    {   $city = I('get.newcity');
        if(!empty($_FILES['file']['tmp_name'])){
            $upload = new \Think\Upload();// 实例化上传类    
            $upload->maxSize   =     3145728;// 设置附件上传大小    
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
            $upload->savePath  =      'Uploads/'; // 设置附件上传目录    
            // 上传单个文件     
            $info   =   $upload->uploadOne($_FILES['file']);    
            if(!$info) {// 上传错误提示错误信息        
                $this->error($upload->getError());
            }else{
            // 上传成功 获取上传文件信息         
                $face =  '/Uploads'.'/'.$info['savepath'].$info['savename'];   
                //echo $face; 
                //原图入库赋值
                //$data['face'] = $face;
                M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('sfz_img',$face);
            }
        }
        $this->redirect('mobile/info/ls_info',array('newcity'=>$city));
    }
    //教师证修改
    public function jiaoshizheng_img()
    {   $city = I('get.newcity');
        if(!empty($_FILES['file']['tmp_name'])){
            $upload = new \Think\Upload();// 实例化上传类    
            $upload->maxSize   =     3145728 ;// 设置附件上传大小    
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
            $upload->savePath  =      'Uploads/'; // 设置附件上传目录    
            // 上传单个文件     
            $info   =   $upload->uploadOne($_FILES['file']);    
            if(!$info) {// 上传错误提示错误信息        
                $this->error($upload->getError());
            }else{
            // 上传成功 获取上传文件信息         
                $face =  '/Uploads'.'/'.$info['savepath'].$info['savename'];   
                M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('jiaoshizheng_img',$face);
            }
        }
        $this->redirect('mobile/info/ls_info',array('newcity'=>$city));
    }
    //其它证件 毕业证/学位证  修改
    public function qitazheng_img()
    {   $city = I('get.newcity');
        if(!empty($_FILES['file']['tmp_name'])){
            $upload = new \Think\Upload();// 实例化上传类    
            $upload->maxSize   =     3145728 ;// 设置附件上传大小    
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
            $upload->savePath  =      'Uploads/'; // 设置附件上传目录    
            // 上传单个文件     
            $info   =   $upload->uploadOne($_FILES['file']);    
            if(!$info) {// 上传错误提示错误信息        
                //$this->error($upload->getError());
            }else{
            // 上传成功 获取上传文件信息         
                $face =  '/Uploads'.'/'.$info['savepath'].$info['savename'];   
                M('laoshi_user')->where(array('id'=>$_SESSION['id']))->setField('qitazheng_img',$face);
            }
        }
        $this->redirect('mobile/info/ls_info',array('newcity'=>$city));
    }
    //老师个人主页 基本资料添加 显示
    public function ls_jiben()
    {
        //城市显示
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);

        $citys = M('city')->where('parent_id=0')->select();
        $this->assign('citys',$citys);

        $id = I('get.id');
        $sql = "select id,phone,sex,name,education,school,major,city,create_time from laoshi_user where id='{$id}'";
        $laoshi = M()->query($sql);
        $this->assign('laoshi',current($laoshi));

        $this->display();
    }
    //老师个人主页 基本资料添加
    public function ls_jiben_add()
    {//Array ( [username] => 1 [sex] => 男 [xueli] => 大专 [school] => 111 [zhuanye] => 1111 [city] => 广州 )
        if (IS_POST) {
            $data['name'] = I('post.username');
            $data['sex'] = I('post.sex');
            $data['education'] = I('post.xueli');
            $data['school'] = I('post.school');
            $data['major'] = I('zhuanye');
            $data['city'] = I('post.city');

            $id = I('post.id');

            //默认头像
            if ($data['sex'] == '男') {
                $data['face'] = "/Uploads/face/man.jpg";
            }else {
                $data['face'] = "/Uploads/face/woman.jpg";
            }

            //更新
            $res = M('laoshi_user')->where(array('id'=>$id))->save($data);
            if ($res) {
                $url = U('mobile/info/ls_showke',array('id'=>$id,'newcity'=>$data['city']));
                $arr = array(
                    'error' => 1,
                    'info' => '更新成功',
                    'url' => $url 
                    );
                echo json_encode($arr);
            }else {
                $arr = array(
                    'error' => 0,
                    'info' => '重复提交'    
                    );
                echo json_encode($arr);
            }
        }
    }
    //银行卡信息显示
    public function ls_bank()
    {
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);

      $id = I('get.id');
      $this->assign('id',$id);

      $bank = M('bank')->where(array('uid'=>$id))->find();
      $this->assign('bank',$bank);

      $this->display();
    }
    //银行卡信息 添加/更新
    public function ls_bank_add()
    {//Array ( [bank_name] => xxx [bank_addr] => xx [bank] => 中国工商银行 [bank_num] => xxxxx [id] => 15 )
        if (IS_POST) {
            $data['uid'] = I('post.id');
            $data['is_who'] = 'laoshi';

            $data['bank_name'] = I('post.bank_name');
            $data['bank_addr'] = I('post.bank_addr');
            $data['bank'] = I('post.bank');
            $data['bank_num'] = I('post.bank_num');

            $str = "/^(\d{16}|\d{19})$/";
            $bank_num_yz = preg_match($str, $data['bank_num']);
             if (!$bank_num_yz) {
                $arr = array(
                    'error' => 0,
                    'info' => '请输入正确的银行卡号'
                    );
                echo json_encode($arr);
                exit;
             }

            //检测是否绑定银行卡 存在 跟新 不存在 添加 
            $uid = M('bank')->where(array('uid'=>$data['uid']))->find();
            if ($uid) {
                $res = M('bank')->where(array('uid'=>$data['uid']))->save($data);
                if ($res) {
                    $arr = array(
                        'error' => 1,
                        'info' => '更新成功'    
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '重复提交'    
                        );
                    echo json_encode($arr);
                }
            }else {
                $res = M('bank')->add($data);
                if ($res) {
                    $arr = array(
                        'error' => 1,
                        'info' => '添加成功'    
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '添加失败'    
                        );
                    echo json_encode($arr);
                }
            }
        }
    }
    //老师授课信息显示
    public function ls_showke()
    {
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);

        $id = I('get.id');
        $this->assign('id',$id);
        //城市对应的区
        $city_name = M('laoshi_user')->where(array('id'=>$id))->getField('city');
        $cityid = M('city')->where(array('city_name'=>$city_name))->getField('cityid');
        $city_quyu = M('city')->where(array('parent_id'=>$cityid))->select();
        $this->assign('city_quyu',$city_quyu);

        //授课详细信息
        $showke_info = M('showke_info')->where(array('uid'=>$id))->find();
        $this->assign('showke_info',$showke_info);

        $showke_grades = explode(',', $showke_info['grades']);
        $this->assign('showke_grades',$showke_grades);

        $showke_methods = explode(',', $showke_info['methods']);
        $this->assign('showke_methods',$showke_methods);

      //$showke_info['shouke_time']转数组
      $shouke_times = explode(',', $showke_info['shouke_time']);
      $this->assign('shouke_times',$shouke_times);

        //科目
        $subjects = M('subjects')->select();
        $this->assign('subjects',$subjects);

        //年级
        $grades = M('grade')->where('parent_id=0')->select();
        //删除高三初三六年级 1 5 10
        foreach ($grades as $k => $v) {
            if (in_array(1, $v)) {
                unset($grades[$k]);
            }
            if (in_array(5, $v)) {
                unset($grades[$k]);
            }
            if (in_array(10, $v)) {
                unset($grades[$k]);
            }
        }
        $this->assign('grades',$grades);

        //上课方式
        $methods = M('teachingmethod')->select();
        $this->assign('methods',$methods);

      //授课时间段显示 上午
      $showke_time_sw = M('showke_time')->where(array('time_name'=>'上午'))->select();
      $this->assign('showke_time_sw',$showke_time_sw);
      //授课时间段显示 下午
      $showke_time_xw = M('showke_time')->where(array('time_name'=>'下午'))->select();
      $this->assign('showke_time_xw',$showke_time_xw);
      //授课时间段显示 晚上
      $showke_time_ws = M('showke_time')->where(array('time_name'=>'晚上'))->select();
      $this->assign('showke_time_ws',$showke_time_ws);

        $this->display();
    }
    //授课信息 添加/更新
    public function ls_showke_add()
    {
        if (IS_POST) {
            $data['uid'] = I('post.id');

            $city = I('post.newcity');

            $data['sk_city'] = I('post.sk_city');
            $data['subject'] = I('post.subject');
            $data['address'] = I('post.address');
            $data['price'] = I('post.price');

            $sm_shijian = implode(',', I('post.sm_shijian'));
            $data['shouke_time'] = $sm_shijian;

            $grade = I('post.grade');
            //年级不能为空
            if (empty($grade)) {
                $arr = array(
                    'error' => 0,
                    'info' => '授课年级不能为空'    
                    );
                echo json_encode($arr);
                exit;
            }
            //年级选择不能超过6
            $count_grade = count($grade);
            if ($count_grade > 6) {
                $arr = array(
                    'error' => 0,
                    'info' => '年级选择不能超过6个哦'    
                    );
                echo json_encode($arr);
                exit;
            }
            $data['grades'] = implode(',', $grade);
            $methods = I('post.methods');
            //授课方式不能为空
            if (empty($methods)) {
                $arr = array(
                    'error' => 0,
                    'info' => '授课方式不能为空'    
                    );
                echo json_encode($arr);
                exit;
            }
            $data['methods'] = implode(',', $methods);

            //入库
            //检测老师授课信息存在 跟新 不存在 添加 
            $uid = M('showke_info')->where(array('uid'=>$data['uid']))->find();
            if ($uid) {
                $res = M('showke_info')->where(array('uid'=>$data['uid']))->save($data);
                if ($res) {
                    $url = U('mobile/info/ls_jiaoling',array('id'=>$data['uid'],'newcity'=>$city));
                    $arr = array(
                        'error' => 1,
                        'info' => '更新成功',
                        'url' => $url  
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '重复提交'    
                        );
                    echo json_encode($arr);
                }
            }else {
                $res = M('showke_info')->add($data);
                if ($res) {
                    $url = U('mobile/info/ls_jiaoling',array('id'=>$data['uid'],'newcity'=>$city));
                    $arr = array(
                        'error' => 1,
                        'info' => '添加成功',
                        'url' => $url  
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '添加失败'    
                        );
                    echo json_encode($arr);
                }
            }
        }
    }
    //教龄经历显示
    public function ls_jiaoling()
    {
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);

        $id = I('get.id');
        $this->assign('id',$id);

      $jiaoling_jli = M('jiaoling_jli')->where(array('uid'=>$id))->find();
      $this->assign('jiaoling_jli',$jiaoling_jli);

      //学生类型
      $jiaoling_jli_stye = explode(',', $jiaoling_jli['stu_stye']);
      $this->assign('jiaoling_jli_stye',$jiaoling_jli_stye);
      //老师特点
      $jiaoling_jli_tedian = explode(',', $jiaoling_jli['laoshi_stye']);
      $this->assign('jiaoling_jli_tedian',$jiaoling_jli_tedian);

        $this->display();
    }
    //教龄经历 添加/更新
    public function ls_jiaoling_add()
    {
      if (IS_POST) {
            $data['jiaoling'] = I('post.jiaoling');

            $data['start_year'] = I('post.start_year');
            $data['start_month'] = I('post.start_month');
            $data['stop_year'] = I('post.stop_year');
            $data['stop_month'] = I('post.stop_month');

            $data['experience'] = I('post.content');
            $data['jianjie'] = I('post.jianjie');

            $stu_stye = I('post.stye_one').','.I('post.stye_two').','.I('post.stye_three');
            $data['stu_stye'] = $stu_stye;
            $laoshi_stye = I('post.tedian_one').','.I('post.tedian_two').','.I('post.tedian_three');
            $data['laoshi_stye'] = $laoshi_stye;

            $data['uid'] = I('post.id');
            $data['create_time'] = time();

            $city = I('post.newcity');

            //检测老师经历存在 跟新 不存在 添加 
            $uid = M('jiaoling_jli')->where(array('uid'=>$data['uid']))->find();
            if ($uid) {
                $res = M('jiaoling_jli')->where(array('uid'=>$data['uid']))->save($data);
                if ($res) {
                    $url = U('mobile/info/ls_home',array('id'=>$data['uid'],'newcity'=>$city));
                    $arr = array(
                        'error' => 1,
                        'info' => '更新成功',
                        'url' => $url   
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '重复提交'    
                        );
                    echo json_encode($arr);
                }
            }else {
                $res = M('jiaoling_jli')->add($data);
                if ($res) {
                    $url = U('mobile/info/ls_home',array('id'=>$data['uid'],'newcity'=>$city));
                    $arr = array(
                        'error' => 1,
                        'info' => '添加成功',
                        'url' => $url  
                        );
                    echo json_encode($arr);
                }else {
                    $arr = array(
                        'error' => 0,
                        'info' => '添加失败'    
                        );
                    echo json_encode($arr);
                }
            }
      }
    }
    //成功案例显示
    public function ls_success()
    {
        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);
        
        $id = I('get.id');
        $this->assign('id',$id);

      //最近的成功案例显示
      $success = M('success_case')->where(array('uid'=>$id))->order('create_time desc')->select();
      $this->assign('success',$success);

        $this->display();
    }
    //成功案例 添加
    public function ls_success_add()
    {//Array ( [start_year] => 1980 [start_month] => 2 [name] => x [school] => xx [content] => xxxx [id] => )
      if (IS_POST) {
          $data['uid'] = I('post.id');

          $data['time_year'] = I('post.start_year');
          $data['time_month'] = I('post.start_month');
          $data['stu_name'] = I('post.name');
          $data['school'] = I('post.school');
          $data['result'] = I('post.content');
          $data['create_time'] = time();

          $res = M('success_case')->add($data);
          if ($res) {
              $arr = array(
                  'error' => 1,
                  'info' => '添加成功'    
                  );
              echo json_encode($arr);
          }else {
              $arr = array(
                  'error' => 0,
                  'info' => '添加失败'    
                  );
              echo json_encode($arr);
          }
      }
    }


    //老师预定课程
    public function ls_my_yuyue()
    {
        //预约订单显示
        $sql = "select t1.*,t2.phone,t3.name from jz_to_ls_yuyue t1 inner join jiazhang_user t2 on t1.ls_uid=t2.id inner join jiazhang_xuqiu t3 on t1.jz_uid=t3.uid where t1.ls_uid='{$_SESSION['id']}' and is_shenhe=0";
        $yuyues = M()->query($sql);
        $this->assign('yuyues',$yuyues);

        $this->display();
    }
    //老师预约订单 取消 删除
    public function ls_order_del()
    {
        if (IS_POST) {
            $id = I('post.id');
            $res = M('jz_to_ls_yuyue')->delete($id);
            if ($res) {
                 $arr = array(
                        'error' =>1,
                        'info'=>"取消成功"
                        );
                echo json_encode($arr);
            }else {
                 $arr = array(
                        'error' =>0,
                        'info'=>"取消失败"
                        );
                echo json_encode($arr);
            }
        }
    }
    //老师预约订单 接受 
    public function jieshou_on()
    {
        if (IS_POST) {
            $id = I('post.id');
            $res = M('jz_to_ls_yuyue')->where(array('id'=>$id))->setField('is_laoshi_on',1);
            if ($res) {
                 $arr = array(
                        'error' =>1,
                        'info'=>"接受成功,请尽快连接课程顾问,尽快连接学生上课"
                        );
                echo json_encode($arr);
            }else {
                 $arr = array(
                        'error' =>0,
                        'info'=>"接受失败,重新在接受"
                        );
                echo json_encode($arr);
            }
        }
    }
    //老师我的课程
    public function ls_my_order()
    {
        //我的课程显示
        $sql = "select t1.*,t2.phone,t3.name from jz_to_ls_yuyue t1 inner join jiazhang_user t2 on t1.jz_uid=t2.id inner join jiazhang_xuqiu t3 on t1.jz_uid=t3.uid where t1.ls_uid='{$_SESSION['id']}' and is_laoshi_on=1 and is_shenhe=1";
        $orders = M()->query($sql);
        $this->assign('orders',$orders);

        $this->display();
    }


    //家长个人主页
    public function jz_home()
    {
        if ($_SESSION['is_who'] != 'jiazhang') {
            $this->redirect('mobile/user/logout');
            exit;
        }

        //首页显示城市
        $city = I('get.newcity')?I('get.newcity'):'广州';
        $this->assign('city',$city);

        //老师信息
        $jiazhang_info = M('jiazhang_user')->field('id,phone,face')->where(array('id'=>$_SESSION['id']))->find();
        $this->assign('jiazhang_info',$jiazhang_info);

        $this->display();
    }
    //家长个人主页 家长需求基本信息
    public function jz_info()
    {
      //首页显示城市
      $city = I('get.newcity')?I('get.newcity'):'广州';
      $this->assign('city',$city);

        $id = I('get.id');
        $jiazhang = M('jiazhang_xuqiu')->where(array('uid'=>$id))->find();
        $this->assign('jiazhang',$jiazhang);

        //授课方式 跟上面字段(1,2,3,4) 匹配对应ID跟name显示
        $subjects = M('subjects')->select();
        $this->assign('subjects',$subjects);


        $this->display();
    }
    //家长个人主页 基本信息添加 显示
    public function jz_jiben()
    {
      //首页显示城市
      $city = I('get.newcity')?I('get.newcity'):'广州';
      $this->assign('city',$city);

    $citys = M('city')->where('parent_id=0')->select();
    $this->assign('citys',$citys);
      
      $id = I('get.id');
      $sql = "select id,phone,sex,name,city,create_time from jiazhang_user where id='{$id}'";
      $jiazhang = M()->query($sql);
      $this->assign('jiazhang',current($jiazhang));

        $this->display();
    }
    //家长个人主页 基本信息添加/更新
    public function jz_jiben_add()
    {   //Array ( [username] => 李先生 [sex] => 男 [city] => [id] => 1 )
      if (IS_POST) {
        //f$data['phone'] = I('post.phone');
        $data['name'] = I('post.username');
        $data['sex'] = I('post.sex');
        $data['city'] = I('post.city');

        $id = I('post.id');

        //更新
        $res = M('jiazhang_user')->where(array('id'=>$id))->save($data);
            if ($res) {
                $url = U('mobile/info/jz_xuqiu',array('id'=>$id,'newcity'=>$data['city']));
                $arr = array(
                    'error' => 1,
                    'info' => '更新成功',
                    'url' => $url
                    );
                echo json_encode($arr);
            }else {
                $arr = array(
                    'error' => 0,
                    'info' => '重复提交'    
                    );
                echo json_encode($arr);
            }
      }
    }
    //家长需求信息 显示
    public function jz_xuqiu()
    {
      $id = I('get.id');
      $this->assign('id',$id);

      $city_name = M('jiazhang_user')->where(array('id'=>$id))->getField('city');
      $this->assign('city_name',$city_name);

      $cityid = M('city')->where(array('city_name'=>$city_name))->getField('cityid');

      //对应区域
      $city_quyu = M('city')->where(array('parent_id'=>$cityid))->select();
      $this->assign('city_quyu',$city_quyu);

      //上课年级
      $grades = M('grade')->where('parent_id=0')->select();
      $this->assign('grades',$grades);

      //需求信息
      $jiazhang_xuqiu = M('jiazhang_xuqiu')->where(array('uid'=>$id))->find();
      $this->assign('jiazhang_xuqiu',$jiazhang_xuqiu);

      $jiazhang_xuqiu_subjects = explode(',', $jiazhang_xuqiu['subjects']);
      $this->assign('jiazhang_xuqiu_subjects',$jiazhang_xuqiu_subjects);
      //科目显示
      $kecheng = M('subjects')->select();
      $this->assign('kecheng',$kecheng);

        $this->display();
    }
    //家长需求信息 添加/更新
    public function jz_xuqiu_add()
    {//Array ( [quyu] => 白云区 [name] => 李四 [sex] => 男 [grade] => 高二 [kecheng] => Array ( [0] => 1 [1] => 2 [2] => 4 ) [id] => 1 [sk_city] => 广州 )
      if (IS_POST) {
        $data['sk_city'] = I('post.sk_city');
        $data['sk_quyu'] = I('post.quyu');
        $data['name'] = I('post.name');
        $data['sex'] = I('post.sex');
        $data['grade'] = I('post.grade');

        $kecheng = I('post.kecheng');
        $data['subjects'] = implode(',', $kecheng);

        $data['uid'] = I('post.id');

        $uid = M('jiazhang_xuqiu')->where(array('uid'=>$data['uid']))->getField('uid');
        if ($uid) {
          $res = M('jiazhang_xuqiu')->where(array('uid'=>$data['uid']))->save($data);
          if ($res) {
               $url = U('mobile/info/jz_home',array('newcity'=>$data['sk_city']));
               $arr = array(
                      'error' =>1,
                      'info'=>"更新成功",
                      'url' => $url
                      );
              echo json_encode($arr);
          }else {
               $arr = array(
                      'error' =>0,
                      'info'=>"重复提交"
                      );
              echo json_encode($arr);
          }
        }else {
          $res = M('jiazhang_xuqiu')->add($data);
          if ($res) {
                $url = U('mobile/info/jz_home',array('newcity'=>$data['sk_city']));
               $arr = array(
                      'error' =>1,
                      'info'=>"添加成功",
                      'url' => $url
                      );
              echo json_encode($arr);
          }else {
               $arr = array(
                      'error' =>0,
                      'info'=>"添加失败"
                      );
              echo json_encode($arr);
          }
        }
      }
    }


    //家长我的预定
    public function jz_my_yuyue()
    {
      //首页显示城市
      $city = I('get.newcity')?I('get.newcity'):'广州';
      $this->assign('city',$city);

        //我的预约显示
        $sql = "select t1.*,t2.name,t2.face,t2.phone from jz_to_ls_yuyue t1 inner join laoshi_user t2 on t1.ls_uid=t2.id where t1.jz_uid='{$_SESSION['id']}' and is_shenhe=0";
        $yuyues = M()->query($sql);
        $this->assign('yuyues',$yuyues);

        $this->display();
    }
    //家长预定单 取消 删除
    public function jz_order_del()
    {
        if (IS_POST) {
            $id = I('post.id');
            $res = M('jz_to_ls_yuyue')->delete($id);
            if ($res) {
                 $arr = array(
                        'error' =>1,
                        'info'=>"取消成功"
                        );
                echo json_encode($arr);
            }else {
                 $arr = array(
                        'error' =>0,
                        'info'=>"取消失败"
                        );
                echo json_encode($arr);
            }
        }
    }

    //家长我的订单
    public function jz_my_order()
    {
      //首页显示城市
      $city = I('get.newcity')?I('get.newcity'):'广州';
      $this->assign('city',$city);

        //我的订单显示
        $sql = "select t1.*,t2.name,t2.face,t2.phone from jz_to_ls_yuyue t1 inner join laoshi_user t2 on t1.ls_uid=t2.id where t1.jz_uid='{$_SESSION['id']}' and is_laoshi_on=1 and is_shenhe=1";
        $orders = M()->query($sql);
        $this->assign('orders',$orders);

        $this->display();
    }








}